package com.hunan.api.catv.service.biz.ding;

import com.google.gson.JsonObject;
import com.hunan.api.catv.entity.ServiceResult;
import com.hunan.api.catv.mq.MqConstants;
import com.hunan.api.catv.service.ResultService;
import com.hunan.api.catv.service.biz.cache.CacheBiz;
import com.hunan.api.catv.service.biz.mq.MqBiz;
import com.hunan.api.catv.service.biz.system.SystemDictBiz;
import com.hunan.api.catv.service.impl.ding.DingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class DingBiz extends ResultService {
    @Autowired
    DingService dingService;

    @Autowired
    CacheBiz cacheBiz;

    @Autowired
    SystemDictBiz systemDictBiz;

    @Autowired
    MqBiz mqBiz;


    public void dingNotify(String title, String message) {
        String server = cacheBiz.getSystemDict("ding_server");
        dingService.dingNotify(title, message, server);
    }

    public ServiceResult dingNotify(String text, Integer dingType) {
        JsonObject msg = new JsonObject();
        msg.addProperty("type", dingType);
        msg.addProperty("text", text);
        ServiceResult result = mqBiz.push(MqConstants.ding_warning_exchange, MqConstants.ding_warning_key, msg.toString());
        if (result.getStatus()) {
            return buildOK("", "");
        }
        return buildFail(false, "");
    }

    public void atNotify(String title, String message, String atPhone) {
        String server = cacheBiz.getSystemDict("ding_server");
        dingService.atNotify(title, message, atPhone, server);
    }
}
